﻿<html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
            企业进销存系统
        </title>
        <link rel="stylesheet" href="./css/common.css" type="text/css" media="screen"/>
        <script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script> 
    </head>
    
    <body >
        <div class='button'  onclick='clickinsert();'>添加网点</div>
        <div class="tableremain" id="xixi1">
            <table>
                <tr>
                    <td style="width:150px">网点编号</td>
                    <td style="width:250px">网点名称</td>
                    <td style="width:150px">网点地址</td>
                    <td style="width:250px">备注</td>
                    <td style="width:150px">修改</td>
                </tr>
                <tr>
                    <td>asd</td>
                    <td class='netName'>asd</td>
                    <td>asd</td>
                    <td>asd</td>
                    <td><div class='button'  onclick='clickModify(this);'>修改</div> <div class='button'>删除</div></td>
                </tr>
                <tr>
                    <td>asd</td>
                    <td>asd</td>
                    <td>asd</td>
                    <td>asd</td>
                    <td><div class='button'>修改</div> <div class='button'>删除</div></td>
                </tr>
                <tr>
                    <td>asd</td>
                    <td>asd</td>
                    <td>asd</td>
                    <td>asd</td>
                    <td><div class='button'>修改</div> <div class='button'>删除</div></td>
                </tr>
            </table>
        </div>
        <div class="messages1">
            <label class="pwdl">网点名称：</label><label id='mname'></label><br/>
            <label class="pwdl">地址：</label><input type='text' id='maddress'/><br/>
            <label class="pwdl">备注：</label><br/><textarea id="mremarks"></textarea><br/>
            <INPUT TYPE="hidden" id="id"/>
            <div style="text-align:center;width:250px">
                <div class='button' onclick='clickLogm();'>修改</div>
                <button type="reset" class="pwdbb" id="cancelpwd">重置</button>
            </div>
        </div>
        <div class="messages2">
            <label class="pwdl">网点名称：</label><input type='text' id='iname'/><br/>
            <label class="pwdl">地址：</label><input type='text' id='iaddress'/><br/>
            <label class="pwdl">备注：</label><br/><textarea id="iremarks"></textarea><br/>
            <div style="text-align:center;width:250px">
                <div class='button' onclick='clickLogi();'>添加</div>
                <button type="reset" class="pwdbb" id="cancelpwd">重置</button>
            </div>
        </div>
        
    </body>
    <script>
        
        var a=0;
        $('.messages1').hide();
        $('.messages2').hide();
        function clickModify(gg){
            if(a==0){
                $('.messages1').show();
                a=1;
            }
            else {
                $('.messages1').hide();
                a=0;
            }
            $('#mname').html($(gg).parent().parent().children('.name').html());
            $('#id').val($(gg).parent().parent().children('.id').html());
            $('#maddress').val($(gg).parent().parent().children('.address').html());
            $('#mremarks').val($(gg).parent().parent().children('.bz').html());
        }
        function clickinsert(){
            if(a==0){
                $('.messages2').show();
                a=1;
            }
            else {
                $('.messages2').hide();
                a=0;
            }
            $('#nName').val("");
        }
    </script>

    <script>
        
        $(document).ready(function(){
            $.ajax({
                type : "POST",
                url : "/jxc/getshoplist.do",
                async:false,
                data:{},
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                dataType : 'json',
                success : function(data) {
                    //alert(data.result);
                    if(data.shop=="[]"){
                        
                    }else{
                        aaa="";
                        aaa+='<table><tr style="text-align:center"><td style="width:150px">网点编号</td><td style="width:250px">网点名称</td><td style="width:150px">网点地址</td><td style="width:250px">备注</td><td style="width:150px">修改</td></tr>';
                        $.each(data.result, function(index, shopjson) {
                            aaa+='<tr style="text-align:center"><td class="id">'+shopjson.id+'</td><td class="name">'+shopjson.name+'</td><td class="address">'+shopjson.address+'</td><td class="bz">'+shopjson.bz+'<td><div class="button" onclick="clickModify(this);">修改</div> <div class="button" onclick="clickLogd(this);">删除</div></td></tr>';
                            });
                            aaa+='</table></div>';
                        $("#xixi1").html(aaa);
                    }
                    //$('.tableremain td').attr('class','tabletd');
                    
                },
                error : function(data) {
                   alert("error");
                }                  
            });
        });
    </script>
    <script>
        function clickLogi(){
            $.ajax({
                type : "POST",
                url : "/jxc/addshop.do",
                async:false,
                data:{
                    "name":$(iname).val(),
                    "bz":$(iremarks).val(),
                    "address":$(iaddress).val()
                },
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                dataType : 'json',
                success : function(data) {
                    //alert(data.result);
                    if(data.result==1){
                        alert("网点名称已存在，请重新输入"); 
                    }else{
                        $('.messages2').hide();
                        a=0;
                        $.ajax({
                            type : "POST",
                            url : "/jxc/getshoplist.do",
                            async:false,
                            data:{},
                            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                            dataType : 'json',
                            success : function(data) {
                                //alert(data.result);
                                if(data.shop=="[]"){
                                    
                                }else{
                                    aaa="";
                                    aaa+='<table><tr style="text-align:center"><td style="width:150px">网点编号</td><td style="width:250px">网点名称</td><td style="width:150px">网点地址</td><td style="width:250px">备注</td><td style="width:150px">修改</td></tr>';
                                    $.each(data.result, function(index, shopjson) {
                                        aaa+='<tr style="text-align:center"><td class="id">'+shopjson.id+'</td><td class="name">'+shopjson.name+'</td><td class="address">'+shopjson.address+'</td><td class="bz">'+shopjson.bz+'<td><div class="button" onclick="clickModify(this);">修改</div> <div class="button" onclick="clickLogd(this);">删除</div></td></tr>';
                                        });

                                        aaa+='</table></div>';
                                    $("#xixi1").html(aaa);
                                }
                                //$('.tableremain td').attr('class','tabletd');
                                
                            },
                            error : function(data) {
                               alert("error");
                            }                  
                        });
                        
                    }
                    //$('.tableremain td').attr('class','tabletd');
                    
                },
                error : function(data) {
                   alert("error");
                }                  
            });
        }
    </script>
    <script>
        function clickLogm(){
            $.ajax({
                type : "POST",
                url : "/jxc/updateshop.do",
                async:false,
                data:{
                    "name":$(mname).val(),
                    "bz":$(mremarks).val(),
                    "address":$(maddress).val(),
                    "id":$(id).val()
                },
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                dataType : 'json',
                success : function(data) {
                    //alert(data.result);
                    if(data.result==1){
                        alert("网点名称已存在，请重新输入"); 
                    }else{
                        $('.messages1').hide();
                        a=0;
                        $.ajax({
                            type : "POST",
                            url : "/jxc/getshoplist.do",
                            async:false,
                            data:{},
                            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                            dataType : 'json',
                            success : function(data) {
                                //alert(data.result);
                                if(data.shop=="[]"){
                                    
                                }else{
                                    aaa="";
                                    aaa+='<table><tr style="text-align:center"><td style="width:150px">网点编号</td><td style="width:250px">网点名称</td><td style="width:150px">网点地址</td><td style="width:250px">备注</td><td style="width:150px">修改</td></tr>';
                                    $.each(data.result, function(index, shopjson) {
                                        aaa+='<tr style="text-align:center"><td class="id">'+shopjson.id+'</td><td class="name">'+shopjson.name+'</td><td class="address">'+shopjson.address+'</td><td class="bz">'+shopjson.bz+'<td><div class="button" onclick="clickModify(this);">修改</div> <div class="button" onclick="clickLogd(this);">删除</div></td></tr>';
                                        });
                                        aaa+='</table></div>';
                                    $("#xixi1").html(aaa);
                                }
                                //$('.tableremain td').attr('class','tabletd');
                                
                            },
                            error : function(data) {
                               alert("error");
                            }                  
                        });
                        
                    }
                    //$('.tableremain td').attr('class','tabletd');
                    
                },
                error : function(data) {
                   alert("error");
                }                  
            });
        }
    </script>
    <script>
        function clickLogd(gg){
            $.ajax({
                type : "POST",
                url : "/jxc/deleteshop.do",
                async:false,
                data:{
                    "id":$(gg).parent().parent().children('.id').html()
                },
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                dataType : 'json',
                success : function(data) {
                    //alert(data.result);
                    if(data.result==""){
                        //alert("网点名称已存在，请重新输入"); 
                    }else{
                        $.ajax({
                            type : "POST",
                            url : "/jxc/getshoplist.do",
                            async:false,
                            data:{},
                            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                            dataType : 'json',
                            success : function(data) {
                                //alert(data.result);
                                if(data.shop=="[]"){
                                    
                                }else{
                                    aaa="";
                                    aaa+='<table><tr style="text-align:center"><td style="width:150px">网点编号</td><td style="width:250px">网点名称</td><td style="width:150px">网点地址</td><td style="width:250px">备注</td><td style="width:150px">修改</td></tr>';
                                    $.each(data.result, function(index, shopjson) {
                                        aaa+='<tr style="text-align:center"><td class="id">'+shopjson.id+'</td><td class="name">'+shopjson.name+'</td><td class="address">'+shopjson.address+'</td><td class="bz">'+shopjson.bz+'<td><div class="button" onclick="clickModify(this);">修改</div> <div class="button" onclick="clickLogd(this);">删除</div></td></tr>';
                                        });
                                        aaa+='</table></div>';
                                    $("#xixi1").html(aaa);
                                }
                                //$('.tableremain td').attr('class','tabletd');
                                
                            },
                            error : function(data) {
                               alert("error");
                            }                  
                        });
                        
                    }
                    //$('.tableremain td').attr('class','tabletd');
                    
                },
                error : function(data) {
                   alert("error");
                }                  
            });
        }
    </script>

</html>